package com.wc.alorithm_blue_bridge._二分.Q3346;

import java.io.*;
/**
 * @Author congege
 * @Description
 *
 *
 * 最大通过数
 * https://www.lanqiao.cn/problems/3346/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/24-22:29
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        long[] array1 = new long[n + 1];
        long[] array2 = new long[m + 1];
        for(int i = 1; i <= n; i++){
            array1[i] = array1[i - 1] + sc.nextInt();
        }

        for(int i = 1; i <= m; i++){
            array2[i] = array2[i - 1] + sc.nextInt();
        }
        int ans = 0;
        for(int i = 0; i <= n; i++){
            long val = k - array1[i];
            if (val < 0){
                break;
            }
            int left = 1;
            int right = m;
            int mid;
            while(left <= right){
                mid = left + (right - left) / 2;
                if(array2[mid] > val){
                    right = mid - 1;
                }else if (array2[mid] < val){
                    left = mid + 1;
                }else {
                    left = mid + 1;
                    break;
                }
            }
            ans = Math.max(ans,left - 1 + i);
        }
        System.out.println(ans);
    }

    static class Input{
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (Exception e) {
                return -1;
            }

            return (int) in.nval;
        }
    }
}
